package com.classtest.classtestdemo.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.classtest.classtestdemo.bean.DbGoods;
import com.classtest.classtestdemo.bean.Limit;
import com.classtest.classtestdemo.mapper.DbGoodsMapper;
import com.classtest.classtestdemo.mapper.DbUserMapper;
import com.classtest.classtestdemo.service.DbGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class DbGoodsServiceImpl extends ServiceImpl<DbGoodsMapper, DbGoods> implements DbGoodsService {
    @Autowired
    DbGoodsMapper dbGoodsMapper;

    @Override
    public List<DbGoods> fuzzySearchAll(String json) {
        Limit limit = JSONObject.parseObject(json, Limit.class);
        return dbGoodsMapper.fuzzySearch(limit.getDown(),limit.getUp(),limit.getSearchName());
    }

    @Override
    public List<DbGoods> selectAll(int down,int up) {
        return dbGoodsMapper.selectAll(down,up);
    }

    @Override
    public int selectCount() {
        return dbGoodsMapper.selectCount();
    }

    @Override
    public int fuzzyCount(String json) {
        DbGoods dbGoods = JSONObject.parseObject(json, DbGoods.class);
        return dbGoodsMapper.fuzzyCount(dbGoods);
    }

    @Override
    public void UpdateCountByGsId(String gsId, int count) {
        dbGoodsMapper.UpdateCountByGsId(gsId,count);
    }

    @Override
    public List<DbGoods> selectByGsId(String gsId) {
        return dbGoodsMapper.selectByGsId(gsId);
    }

}
